package com.ruoyi.web.domain.incomeexpense;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.pojo.dto.incomeexpense.IncomeExpensePage;
import com.ruoyi.web.pojo.request.incomeexpense.IncomeExpenseAdd;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 支入支出对象 tt_income_expense
 * 
 * @author zq
 * @date 2024-01-09
 */
@Api("支入支出")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class IncomeExpense extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** id */
    @ApiModelProperty(value = "id")
    private Long id;

    /** 用户ID */
    @Excel(name = "用户ID")
    private Long userId;

    /** 支入支出分类 */
    @Excel(name = "支入支出分类")
    private String typeId;

    /** 子分类 */
    @Excel(name = "子分类")
    private String childId;

    /** 金额 */
    @ApiModelProperty(value = "金额(元)")
    @Excel(name = "金额(元)")
    private BigDecimal money;

    /** 名称 */
    @ApiModelProperty(value = "名称 对应（租赁收入:出租对象,捐赠收入:来源,支出利息:还款对象,支付租金:支付对象,）")
    @Excel(name = "名称")
    private String name;

    /** 记录时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "记录时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date recordDate;

    /** 单价（元） */
    @ApiModelProperty(value = "单价（元）")
    @Excel(name = "单价", readConverterExp = "元=")
    private BigDecimal price;

    /** 数量 */
    @ApiModelProperty(value = "数量,对应（购买保险：投保数量）")
    @Excel(name = "数量")
    private Long number;

    /** 单位 */
    @ApiModelProperty(value = "单位")
    @Excel(name = "单位")
    private String unit;

    /** 附件 */
    @Excel(name = "附件")
    @ApiModelProperty(value = "附件")
    private String pic;

    /** 删除标志（0代表存在 2代表删除） */
    private String delFlag;

    /** 保险公司 */
    @ApiModelProperty(value = "保险公司")
    @Excel(name = "保险公司")
    private String insuranceCompany;

    /** 保险产品 */
    @ApiModelProperty(value = "保险产品")
    @Excel(name = "保险产品")
    private String insurance;

    @ApiModelProperty("赔付原因")
    private String compensate;

    @ApiModelProperty("搜索使用：开始时间 yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date startTime;

    @ApiModelProperty("搜索使用：结束时间 yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date endTime;

    @ApiModelProperty("搜索使用：开始金额")
    private  BigDecimal startMoney;
    @ApiModelProperty("搜索使用：结束金额")
    private BigDecimal endMoney;

    public static IncomeExpense toIncomeExpense(IncomeExpenseAdd add) {
        if (add == null) {
            return null;
        }
        IncomeExpense bo = new IncomeExpense();
        bo.setTypeId(add.getTypeId());
        bo.setChildId(add.getChildId());
        bo.setMoney(add.getMoney());
        bo.setName(add.getName());
        bo.setRecordDate(add.getRecordDate());
        bo.setPrice(add.getPrice());
        bo.setNumber(add.getNumber());
        bo.setUnit(add.getUnit());
        bo.setPic(add.getPic());
        bo.setInsuranceCompany(add.getInsuranceCompany());
        bo.setInsurance(add.getInsurance());
        bo.setCompensate(add.getCompensate());
        bo.setRemark(add.getRemark());
        // Not mapped IncomeExpense fields:
        // id
        // userId
        return bo;
    }


    public static IncomeExpensePage toIncomeExpensePage(IncomeExpense incomeExpense) {
        if (incomeExpense == null) {
            return null;
        }
        IncomeExpensePage incomeExpensePage = new IncomeExpensePage();
        incomeExpensePage.setId(incomeExpense.getId());
        incomeExpensePage.setUserId(incomeExpense.getUserId());
        incomeExpensePage.setTypeId(incomeExpense.getTypeId());
        incomeExpensePage.setChildId(incomeExpense.getChildId());
        incomeExpensePage.setMoney(incomeExpense.getMoney());
        incomeExpensePage.setName(incomeExpense.getName());
        incomeExpensePage.setRecordDate(incomeExpense.getRecordDate());
        incomeExpensePage.setPrice(incomeExpense.getPrice());
        incomeExpensePage.setNumber(incomeExpense.getNumber());
        incomeExpensePage.setUnit(incomeExpense.getUnit());
        incomeExpensePage.setPic(incomeExpense.getPic());
        incomeExpensePage.setDelFlag(incomeExpense.getDelFlag());
        incomeExpensePage.setInsuranceCompany(incomeExpense.getInsuranceCompany());
        incomeExpensePage.setInsurance(incomeExpense.getInsurance());
        incomeExpensePage.setCompensate(incomeExpense.getCompensate());
        incomeExpensePage.setAccount(SecurityUtils.getLoginUser().getUser().getPhonenumber());
        incomeExpensePage.setUserName(SecurityUtils.getUsername());
        incomeExpensePage.setRemark(incomeExpense.getRemark());
        // Not mapped IncomeExpense fields:
        // startTime
        // endTime
        // startMoney
        // endMoney

        // Not mapped IncomeExpensePage fields:
        // typeName
        // childName
        // state
        return incomeExpensePage;
    }
}
